import matplotlib.pyplot as plt


methods = ['P2PNet', 'HMoDE', 'STEERER', 'BL', 'CLIP-EBC', 'MIANet', 'DLF-IA', 'ThermalCC']
mae = [8.06, 7.75, 7.46, 7.01, 6.98, 6.74, 6.19, 5.8]
fps = [58.38, 45.93, 27.14, 61.71, 42.33, 28.71, 15.45, 50.75]

plt.figure(figsize=(10, 10))
sc = plt.scatter(fps[:5], mae[:5], s=300, c='yellow',  edgecolors='black', alpha=1, zorder=3)
sc = plt.scatter(fps[5:7], mae[5:7], s=300, c='blue',  edgecolors='black', alpha=1, zorder=3)
sc = plt.scatter(fps[7:], mae[7:], s=300, c='green',  edgecolors='black', alpha=1, zorder=3)

# 标注每个点
for i, (x, y) in enumerate(zip(fps, mae)):
    offset_x = 8
    ha = 'left'
    if x > max(fps) - 10:
        offset_x = -10
        ha = 'right'
    plt.annotate(methods[i], 
                (x, y),
                xytext=(offset_x, 10),
                textcoords='offset points',
                ha=ha,
                va='bottom',
                fontsize=18)

plt.xlabel('FPS (Higher is Better)', fontsize=20)
plt.ylabel('MAE (Lower is Better)', fontsize=20)
# plt.title('Performance Comparison: MAE vs FPS', fontsize=28, pad=25)

plt.tick_params(axis='both', which='major', labelsize=20)
plt.grid(True, linestyle='--', alpha=0.7, zorder=0)
plt.xlim(10, 70)
plt.ylim(5.5, 8.5)

# 调整后的箭头位置和样式
plt.annotate('Better', 
            xy=(0.88, 0.18),  # 箭头指向位置
            xytext=(0.75, 0.25),  # 文本起始位置
            xycoords='axes fraction',
            textcoords='axes fraction',
            ha='left', 
            va='center', 
            color='red', 
            fontsize=18,
            arrowprops=dict(
                arrowstyle='->',
                color='red',
                lw=3,
                connectionstyle="arc3,rad=-0.2"  # 添加弧线避免覆盖数据点
            ))

plt.tight_layout()

plt.savefig('performance_com.jpg', 
           dpi=300, 
           bbox_inches='tight', 
           pad_inches=0, 
           transparent=False)

plt.show()